//
//  BKMyOrderRecommendCell.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/7.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderRecommendCell.h"
#import "BK_OD_Tool.h"
@implementation BKMyOrderRecommendCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

-(void)initView{
    _goodsImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_goodsImageView];
    
    _borderIconImageView = [[UIImageView alloc]init];
    _borderIconImageView.hidden = YES;
    [self.contentView addSubview:_borderIconImageView];
    
    _GoodsStateImageView = [[UIImageView alloc]init];
    _GoodsStateImageView.hidden = YES;
    [self.contentView addSubview:_GoodsStateImageView];
    
    _goodsLabel = [[UILabel alloc]init];
    _goodsLabel.textColor = RGB(68, 68, 68);
    _goodsLabel.font = [UIFont systemFontOfSize:13];
    _goodsLabel.numberOfLines = 1;
    
    [self.contentView addSubview:_goodsLabel];
    
    _priceAndMarketLabel = [[UILabel alloc]init];
    [_priceAndMarketLabel setTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_priceAndMarketLabel];
    
    [self makeConstraints];

}

-(void)makeConstraints{
    
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.mas_equalTo(self.mas_top).offset(5);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-40);
        make.width.mas_equalTo(_goodsImageView.mas_height).multipliedBy(1);
    }];
    
    [_borderIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_goodsImageView.mas_left).offset(-5);
        make.top.mas_equalTo(_goodsImageView.mas_bottom).offset(5);
        make.width.mas_equalTo(43);
        make.height.mas_equalTo(14);
    }];
    
    [_GoodsStateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    [_goodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_borderIconImageView.mas_right).offset(3);
        make.top.mas_equalTo(_goodsImageView.mas_bottom).offset(5);
        make.height.mas_equalTo(14);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-3);
    }];
    
    [_priceAndMarketLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_goodsImageView.mas_left).offset(-5);
        make.bottom.mas_equalTo(self.contentView).offset(-1);
        make.right.mas_equalTo(self.contentView).offset(-3);
    }];
    
}

-(void)fillData:(id)data{
    BK_My_Order_CellModel *model = data;
    
    BkMyOrderRecommendModel *recommendModel = model.recommendModel;
    
    [_goodsImageView load:recommendModel.goodsCoverImg placeholderImage:[UIImage imageNamed:@"BKSCpic_newGoods"]];
    _goodsLabel.text = recommendModel.goodsName;

    //商品价
    NSString *goosPriceStr = [NSString stringWithFormat:@"￥%@",recommendModel.goodsPrice];
    //起
    NSString *upTextStr = recommendModel.upText;
    //市场价
    NSString *marketStr = [NSString stringWithFormat:@"￥%@",recommendModel.goodsMarketPrice];

    
    NSString *priceStr = [NSString stringWithFormat:@"%@%@ %@",goosPriceStr,upTextStr,marketStr];
    
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:priceStr ];
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:15.0f]
                    range:NSMakeRange(0, goosPriceStr.length)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:RGB(230, 62, 46) range:NSMakeRange(0, goosPriceStr.length)];
    
    [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:NSMakeRange(goosPriceStr.length, upTextStr.length)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:RGB(178, 178, 178) range:NSMakeRange(goosPriceStr.length, upTextStr.length)];
    
    [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:NSMakeRange(goosPriceStr.length+upTextStr.length+1, marketStr.length)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:RGB(178, 178, 178) range:NSMakeRange(goosPriceStr.length+upTextStr.length + 1, marketStr.length)];
    [attrStr addAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(goosPriceStr.length+upTextStr.length + 1, marketStr.length)];
    _priceAndMarketLabel.attributedText = attrStr;
    
    if ([recommendModel.channelType isEqualToString:@"2"]) {
        _borderIconImageView.hidden = NO;
        _borderIconImageView.image = [UIImage imageNamed:@"BKSCCrossBorder"];
        [_borderIconImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(43);
        }];
        
    }else{
        _borderIconImageView.hidden = YES;
        [_borderIconImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(0);
        }];
    }
    
    if ([recommendModel.status isEqualToString:@"4"]) {
        _GoodsStateImageView.hidden = NO;
        _GoodsStateImageView.image = [UIImage imageNamed:@"BKSCStates"];
    }else{
        _GoodsStateImageView.hidden = YES;
    }
}



@end


@implementation BKMyOrderEmptyCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initView];
    }
    return self;
}

-(void)initView{
    
    self.backgroundColor = ThemeBackgroundColor;
    
    _headScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
    _headScrollView.bounces = NO;
    _headScrollView.scrollEnabled = NO;
    
    _BuyNillImageView = [[UIImageView alloc]init];
    [_headScrollView addSubview:_BuyNillImageView];
    
    _retryButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_retryButton addTarget:self action:@selector(retryButton:) forControlEvents:UIControlEventTouchUpInside];
    [_retryButton setTitleColor:RGB(27, 188, 155) forState:UIControlStateNormal];
    _retryButton.layer.borderColor = RGB(27, 188, 155).CGColor;
    _retryButton.layer.borderWidth = 1.0f;
    _retryButton.titleLabel.font = [UIFont systemFontOfSize:18];
    _retryButton.layer.cornerRadius = 5;
    [_retryButton setTitle:@"刷新" forState:UIControlStateNormal
     ];
    _retryButton.layer.masksToBounds = YES;
    
    [_headScrollView addSubview:_retryButton];
    
    _infoLabel = [[UILabel alloc] init];
    _infoLabel.font = [UIFont systemFontOfSize:15];
    _infoLabel.textColor = RGB(184, 184, 184);
    [_headScrollView addSubview:_infoLabel];
    
    [self.contentView addSubview:_headScrollView];
    [self makeConstraints];
}

-(void)makeConstraints{
    
    _BuyNillImageView.backgroundColor = [UIColor clearColor];
    CGFloat  ratio= 0.66;
    [_BuyNillImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_headScrollView.mas_centerX).offset(0);
        make.centerY.mas_equalTo(_headScrollView.mas_centerY).offset(-25);
        if ([self.status isEqualToString:@"03"]) {
            make.width.mas_equalTo(@(120*ratio));
            make.height.mas_equalTo(@(116*ratio));
        }
        else if ([self.status isEqualToString:@"02"]){
            make.width.mas_equalTo(@(120*ratio));
            make.height.mas_equalTo(@(106*ratio));
        }else if ([self.status isEqualToString:@"01"]){
            make.width.mas_equalTo(@(124*ratio));
            make.height.mas_equalTo(@(106*ratio));
        }else if ([self.status isEqualToString:@""]){
            make.width.mas_equalTo(@(112*ratio));
            make.height.mas_equalTo(@(114*ratio));
        }else if([self.status isEqualToString:@"401"]){
            make.width.mas_equalTo(@(96*ratio));
            make.height.mas_equalTo(@(118*ratio));
        }

    }];
    
    
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_BuyNillImageView.mas_bottom).mas_offset(20);
        make.centerX.mas_equalTo(_headScrollView.mas_centerX);
    }];
    
    //按钮
    [_retryButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_infoLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(_headScrollView.mas_centerX);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
    }];
    
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _headScrollView.frame = self.bounds;
}


-(void)retryButton:(UIButton *)sender{
    if ([self.BK_My_Order_Cell_Delegate respondsToSelector:@selector(refreshButtonClick:)]) {
        [self.BK_My_Order_Cell_Delegate refreshButtonClick:self.status];
        
    }
    
}

- (void)fillData:(id)data{
    
    
    NSString *str = data;
    self.status = str;
    if ([str isEqualToString:@"03"]) {
        _BuyNillImageView.image = [UIImage imageNamed:@"pic_nom_dsh"];
        _infoLabel.text =@"暂无待收货信息";
    }else if ([str isEqualToString:@"02"]){
        _BuyNillImageView.image =[UIImage imageNamed:@"pic_nom_dfh"];
        _infoLabel.text =@"暂无待发货信息";
    }else if ([str isEqualToString:@"01"]){
        _BuyNillImageView.image=[UIImage imageNamed:@"pic_nom_dfk"];
        _infoLabel.text =@"暂无待付款信息";
    }else if ([str isEqualToString:@""]){
        _BuyNillImageView.image=[UIImage imageNamed:@"pic_nom_qbdd"];
        _infoLabel.text =@"暂无订单信息";
    }else if([str isEqualToString:@"401"]){
        _BuyNillImageView.image =[UIImage imageNamed:@"pic_nom_dpj"];
        _infoLabel.text =@"暂无未评价商品";
    }
    [self makeConstraints];
    [self layoutIfNeeded];
  }



@end



